﻿using System.Collections;
using System.Collections.Generic;
using INTEX.DataBase.Tools;
using ReflectionStudio.Core;
using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.IO;
using WPFExcelReport.Helpers;
namespace WPFExcelReport
{
   
    public partial class ITXEXRPT
    {
        public string JLTPrint(ref bool IsReturn)
        {
            if (app.company != "JLT")
                return filename;
            Helper.GetDate(ref date, ref year, ref month, ref day);
            switch (DocType)
            {


                case "JLTWBD10IT":
                    destfolder = SetFolder(Root, "标签");
                    JLTWBD10IT(dsSource);
                    exAgent.Close();
                    IsReturn = true;
                    break;
                case "JLTEK02":
                    destfolder = SetFolder(Root, "采购入库");
                    #region====文件命名==============
                    order = "采购入库_" + date;
                    DestFile = destfolder + "\\" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standard = "JLTEK02";
                    exAgent.CreateNewSheet(temp + ".xls", Standard);
                    tempfile = exAgent.FileName;
                    #endregion
                    JLTEK02(dsSource);
                    break;

                #region======JLTAB==============

                case "JLTVV03PKEN"://订单列表
                case "JLTVV03PKCN"://订单列表
                    lang = "CN";
                    if (DocType.EndsWith("EN"))
                        lang = "EN";
                    destfolder = SetFolder(Root, "发货单");
                    #region====文件命名==============
                    DataRow dwVVLIEF = dsSource.Tables["VVTLIEF"].Rows[0];
                    order = dwVVLIEF["VVTAUFKRS"].ToString().Trim() + dwVVLIEF["VVTAUFLFD"].ToString().Trim() + dwVVLIEF["VVTAUFPOS"].ToString().Trim() + dwVVLIEF["VVTLIEFSCH"].ToString().Trim();
                    DestFile = destfolder + "\\发货单" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standards.Add("JLTVKWZ");
                    Standards.Add("JLTWBLIST");
                    Standards.Add("JLTWBQULIST");
                    exAgent.AddNewSheets(temp + ".xls", Standards);
                    tempfile = exAgent.FileName;
                    #endregion
                    JLTVV03PK(dsSource);
                    break;
                case "JLTAB05BTP":
                    destfolder = SetFolder(Root, "标签");
                    #region====文件命名==============
                    if (!dsSource.Tables.Contains("ABPOS"))
                        IsReturn = true;
                    dwOrder = dsSource.Tables["ABPOS"].Rows[0];
                    if (dwOrder == null)
                    {
                        IsReturn = true;
                    }
                    order = dwOrder["WBBTP"].ToString().Trim();
                    DestFile = destfolder + "\\分批标签" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standard = "JLTAB05BTP";
                    exAgent.CreateNewSheet(temp + ".xls", Standard);
                    tempfile = exAgent.FileName;
                    #endregion
                    JLTAB05BTP();
                    break;
                case "JLTAB55B":
                    destfolder = SetFolder(Root, "生产单");
                    #region====文件命名==============
                    if (!dsSource.Tables.Contains("WB"))
                        IsReturn = true;
                    dwOrder = dsSource.Tables["WB"].Rows[0];
                    if (dwOrder == null)
                    {
                        IsReturn = true;
                    }

                    order = dwOrder["WBBAUFKRS"].ToString().Trim() + dwOrder["WBBAUFLFD"].ToString().Trim() + dwOrder["WBBAUFPOS"].ToString().Trim();
                    DestFile = destfolder + "\\坯布标签" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standard = "JLTAB55B";
                    exAgent.CreateNewSheet(temp + ".xls", Standard);
                    tempfile = exAgent.FileName;
                    #endregion
                    JLTAB55B();
                    break;

                case "JLTAB50DOC":
                    destfolder = SetFolder(Root, "生产单");
                    #region====文件命名==============
                    if (!dsSource.Tables.Contains("ABPOS"))
                        IsReturn = true;
                    dwOrder = dsSource.Tables["ABPOS"].Rows[0];
                    if (dwOrder == null)
                    {
                        IsReturn = true;
                    }
                    order = dwOrder["ORDERNO"].ToString().Trim();
                    DestFile = destfolder + "\\染色流转卡" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standard = "JLTAB50DOC";
                    exAgent.CreateNewSheet(temp + ".xls", Standard);
                    tempfile = exAgent.FileName;
                    #endregion
                    JLTAB50DOC();
                    break;
                case "JLTAB05CARD":
                    destfolder = SetFolder(Root, "生产单");
                    #region====文件命名==============
                    if (!dsSource.Tables.Contains("WBBST"))
                        IsReturn = true;
                    dwOrder = dsSource.Tables["WBBST"].Rows[0];
                    if (dwOrder == null)
                    {
                        IsReturn = true;
                    }
                    order = dwOrder["TP"].ToString().Trim();
                    DestFile = destfolder + "\\布车流转卡" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standards.Add("JLTAB05CARD");
                    //Standards.Add("JLTONAV95BC"); 
                    Standards.Add("JLTAB05WB");
                    exAgent.AddNewSheets(temp + ".xls", Standards);
                    tempfile = exAgent.FileName;
                    #endregion
                    JLTAB05CARD();
                    break;
                case "JLTAB05NWBCARD":
                    destfolder = SetFolder(Root, "生产单");
                    #region====文件命名==============

                    dwOrder = dsSource.Tables["ABPOS"].Rows[0];
                    if (dwOrder == null)
                    {
                        IsReturn = true;
                    }
                    order = dwOrder["WBBTP"].ToString().Trim();
                    DestFile = destfolder + "\\布车流转卡" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standards.Add("JLTAB05CARD");
                    //Standards.Add("JLTONAV95BC"); 
                    Standards.Add("JLTAB05WB");
                    exAgent.AddNewSheets(temp + ".xls", Standards);
                    tempfile = exAgent.FileName;
                    #endregion
                    JLTAB05NWBCARD();
                    break;
                case "JLTAVDOC"://订单列表
                    destfolder = SetFolder(Root, "排产");
                    #region====文件命名==============
                    order = date;
                    DestFile = destfolder + "\\排产" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standard = "JLTAV37DOC";
                    exAgent.CreateNewSheet(temp + ".xls", Standard);
                    tempfile = exAgent.FileName;
                    #endregion
                    JLTAV37DOC(dsSource);
                    break;
                case "JLTONAV95":
                    destfolder = SetFolder(Root, "生产计划");
                    #region====文件命名==============
                    if (!dsSource.Tables.Contains("VKPOS"))
                        IsReturn = true;
                    dwOrder = dsSource.Tables["VKPOS"].Rows[0];
                    if (dwOrder == null)
                    {
                        IsReturn = true;
                    }
                    KRS = dwOrder["VKPAUFKRS"].ToString().Trim();
                    LFD = dwOrder["VKPAUFLFD"].ToString().Trim();
                    POS = dwOrder["VKPAUFPOS"].ToString().Trim();
                    order = KRS + "-" + Helper.GetSubRollNum(LFD) + "-" + Helper.GetSubRollNum(POS);
                    DestFile = destfolder + "\\计划" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standards.Add("JLTONAV95");
                    //Standards.Add("JLTONAV95BC"); 
                    Standards.Add("JLTAV95PLAN");
                    exAgent.AddNewSheets(temp + ".xls", Standards);
                    tempfile = exAgent.FileName;
                    #endregion
                    JLTONAV95(dsSource);
                    break;
                case "JLTCOWS":
                    destfolder = SetFolder(Root, "销售预算");
                    #region====文件命名==============
                    if (!dsSource.Tables.Contains("ICC_VKPRICE"))
                        IsReturn = true;
                    dwOrder = dsSource.Tables["ICC_VKPRICE"].Rows[0];
                    if (dwOrder == null)
                    {
                        IsReturn = true;
                    }
                    KRS = dwOrder["VKPAUFKRS"].ToString().Trim();
                    LFD = dwOrder["VKPAUFLFD"].ToString().Trim();
                    order = KRS + Helper.GetSubRollNum(LFD);
                    DestFile = destfolder + "\\销售预算-" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standard = "JLTCOFS";
                    exAgent.CreateNewSheet(temp + ".xls", Standard);
                    tempfile = exAgent.FileName;
                    #endregion
                    JLTCOWS(dsSource);
                    break;
                case "JLTCOWSLIST":
                    destfolder = SetFolder(Root, "销售预算");
                    #region====文件命名==============
                    order = date;
                    DestFile = destfolder + "\\销售预算-" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standard = "JLTCOWSLIST";
                    exAgent.CreateNewSheet(temp + ".xls", Standard);
                    tempfile = exAgent.FileName;
                    #endregion
                    JLTCOWSLIST(dsSource);
                    break;

                case "JLTAB50AR":
                    destfolder = SetFolder(Root, "配方单");
                    #region====文件命名==============
                    if (!dsSource.Tables.Contains("ABKOPF"))
                        IsReturn = true;
                    dwOrder = dsSource.Tables["ABKOPF"].Rows[0];
                    if (dwOrder == null)
                    {
                        IsReturn = true;
                    }
                    KRS = dwOrder["ABKAUFKRS"].ToString().Trim();
                    LFD = dwOrder["ABKAUFLFD"].ToString().Trim();
                    order = KRS + Helper.GetSubRollNum(LFD);
                    DestFile = destfolder + "\\AR" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standard = "JLTAB50AR";
                    exAgent.CreateNewSheet(temp + ".xls", Standard);
                    tempfile = exAgent.FileName;
                    #endregion
                    JLTAB50AR();
                    break;
                case "JLTRWB18D":
                    destfolder = SetFolder(Root, "坯布检验");
                    #region====文件命名==============
                    order = "坯布疵点明细" + date;
                    DestFile = destfolder + "\\" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standard = "JLTRWB18D";
                    exAgent.CreateNewSheet(temp + ".xls", Standard);
                    tempfile = exAgent.FileName;
                    #endregion
                    JLTRWB18D(dsSource);
                    break;
                case "JLTRWBB13":
                    destfolder = SetFolder(Root, "织造");
                    #region====文件命名==============
                    order = "织机产量表" + date;
                    DestFile = destfolder + "\\" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standard = "JLTRWBB13";
                    exAgent.CreateNewSheet(temp + ".xls", Standard);
                    tempfile = exAgent.FileName;
                    #endregion
                    JLTRWBB13(dsSource);
                    break;
                case "JLTCPWB02":
                    destfolder = SetFolder(Root, "成品细码单");
                    #region====文件命名==============
                    order = "成品细码单" + date;
                    DestFile = destfolder + "\\" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standard = "JLTCPWB02";
                    exAgent.CreateNewSheet(temp + ".xls", Standard);
                    tempfile = exAgent.FileName;
                    #endregion
                    JLTCPWB02(dsSource);
                    break;
                case "JLTWB02":
                    destfolder = SetFolder(Root, "成品库存");
                    #region====文件命名==============
                    order = date;
                    DestFile = destfolder + "\\" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standard = "JLTWB02";
                    exAgent.CreateNewSheet(temp + ".xls", Standard);
                    tempfile = exAgent.FileName;
                    #endregion
                    JLTWB02(dsSource);
                    break;

                case "JLTTD":
                    destfolder = SetFolder(Root, "脱单查询");
                    #region====文件命名==============
                    order = date;
                    DestFile = destfolder + "\\" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standard = "JLTTD";
                    exAgent.CreateNewSheet(temp + ".xls", Standard);
                    tempfile = exAgent.FileName;
                    #endregion
                    JLTTD(dsSource);
                    break;
                case "JLTVKQC":
                    destfolder = SetFolder(Root, "品质自检");
                    #region====文件命名==============
                    if (!dsSource.Tables.Contains("VKPOS"))
                        IsReturn = true;
                    dwOrder = dsSource.Tables["VKPOS"].Rows[0];
                    if (dwOrder == null)
                    {
                        IsReturn = true;
                    }
                    KRS = dwOrder["VKPART"].ToString().Trim();
                    order = KRS;
                    DestFile = destfolder + "\\" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standard = "JLTVKQC";
                    exAgent.CreateNewSheet(temp + ".xls", Standard);
                    tempfile = exAgent.FileName;
                    #endregion
                    JLTVKQC(dsSource);
                    break;

                case "JLTVKSS":
                    destfolder = SetFolder(Root, "销售服务查询");
                    #region====文件命名============== 
                    KRS = "销售服务查询" + date;
                    order = KRS;
                    DestFile = destfolder + "\\" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standard = "JLTVKSS";
                    exAgent.CreateNewSheet(temp + ".xls", Standard);
                    tempfile = exAgent.FileName;
                    #endregion
                    JLTVKSS(dsSource);
                    break;
                case "JLTABGB52":
                    destfolder = SetFolder(Root, "染色查询");
                    #region====文件命名============== 
                    KRS = "染色查询" + date;
                    order = KRS;
                    DestFile = destfolder + "\\" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standard = "JLTABGB52";
                    exAgent.CreateNewSheet(temp + ".xls", Standard);
                    tempfile = exAgent.FileName;
                    #endregion
                    JLTABGB52(dsSource);
                    break;
                case "JLTRWB18DF":
                    destfolder = SetFolder(Root, "坯布检验");
                    #region====文件命名==============
                    order = "坯布疵点明细" + date;
                    DestFile = destfolder + "\\" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standard = "JLTRWB18D";
                    exAgent.CreateNewSheet(temp + ".xls", Standard);
                    tempfile = exAgent.FileName;
                    #endregion
                    JLTRWB18DF(dsSource);
                    break;

                case "JLTGB20LABEL":
                    destfolder = SetFolder(Root, "染批标签");
                    #region====文件命名==============
                    order = System.DateTime.Now.ToFileTime().ToString();
                    DestFile = destfolder + "\\LB" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standards.Add("JLTGB20LABEL");
                    Standards.Add("JLTGB20LABELT");
                    exAgent.AddNewSheets(temp + ".xls", Standards);
                    tempfile = exAgent.FileName;
                    #endregion
                    JLTGB20LABEL();
                    break;
                case "JLTAB45DOC"://浆纱生产单
                    destfolder = SetFolder(Root, "生产单");
                    #region====文件命名==============
                    if (!dsSource.Tables.Contains("ABKOPF"))
                        IsReturn = true;
                    dwOrder = dsSource.Tables["ABKOPF"].Rows[0];
                    if (dwOrder == null)
                    {
                        IsReturn = true;
                    }
                    KRS = dwOrder["ABKAUFKRS"].ToString().Trim();
                    LFD = dwOrder["ABKAUFLFD"].ToString().Trim();
                    order = KRS + Helper.GetSubRollNum(LFD);
                    DestFile = destfolder + "\\AB" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standard = "JLTAB45DOC";
                    exAgent.CreateNewSheet(temp + ".xls", Standard);
                    tempfile = exAgent.FileName;
                    #endregion
                    JLTAB45DOC(dsSource);
                    break;
                case "JLTAB45BCARD":
                    destfolder = SetFolder(Root, "生产单");
                    #region====文件命名==============
                    if (!dsSource.Tables.Contains("ABKOPF"))
                        IsReturn = true;
                    dwOrder = dsSource.Tables["ABKOPF"].Rows[0];
                    if (dwOrder == null)
                    {
                        IsReturn = true;
                    }
                    KRS = dwOrder["ABKAUFKRS"].ToString().Trim();
                    LFD = dwOrder["ABKAUFLFD"].ToString().Trim();
                    order = KRS + Helper.GetSubRollNum(LFD);
                    DestFile = destfolder + "\\AB" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standard = "JLTAB45BCARD";
                    exAgent.CreateNewSheet(temp + ".xls", Standard);
                    tempfile = exAgent.FileName;
                    #endregion
                    JLTAB45DOC(dsSource);
                    break;
                case "JLTAB50GB12":
                    destfolder = SetFolder(Root, "染色单查询");
                    #region====文件命名==============
                    if (!dsSource.Tables.Contains("ABKOPF"))
                        IsReturn = true;
                    dwOrder = dsSource.Tables["ABKOPF"].Rows[0];
                    if (dwOrder == null)
                    {
                        IsReturn = true;
                    }
                    KRS = dwOrder["ABKAUFKRS"].ToString().Trim();
                    LFD = dwOrder["ABKAUFLFD"].ToString().Trim();
                    order = KRS + Helper.GetSubRollNum(LFD);
                    DestFile = destfolder + "\\GB" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standard = "JLTAB50GB12";
                    exAgent.CreateNewSheet(temp + ".xls", Standard);
                    tempfile = exAgent.FileName;
                    #endregion
                    JLTAB50GB12();
                    break;
                case "JLTAB45GY":
                    destfolder = SetFolder(Root, "浆纱工艺");
                    #region====文件命名==============
                    if (!dsSource.Tables.Contains("ABPOS"))
                        IsReturn = true;
                    dwOrder = dsSource.Tables["ABPOS"].Rows[0];
                    if (dwOrder == null)
                    {
                        IsReturn = true;
                    }
                    KRS = dwOrder["ABPAUFKRS"].ToString().Trim();
                    LFD = dwOrder["ABPAUFLFD"].ToString().Trim();
                    order = KRS + Helper.GetSubRollNum(LFD);
                    DestFile = destfolder + "\\GB" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standard = "JLTAB45GY";
                    exAgent.CreateNewSheet(temp + ".xls", Standard);
                    tempfile = exAgent.FileName;
                    #endregion
                    JLTAB45GY(dsSource);
                    break;
                case "JLTBB14":
                    destfolder = SetFolder(Root, "已扫描入库");
                    #region====文件命名==============
                    order = "已扫描入库_" + date;
                    DestFile = destfolder + "\\" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standard = "JLTBB14";
                    exAgent.CreateNewSheet(temp + ".xls", Standard);
                    tempfile = exAgent.FileName;
                    #endregion
                    JLTBB14(dsSource);
                    break;
                case "JLTBB02":
                    destfolder = SetFolder(Root, "织轴查询");
                    #region====文件命名==============
                    order = "织轴查询";
                    DestFile = destfolder + "\\" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standard = "JLTBB02";
                    exAgent.CreateNewSheet(temp + ".xls", Standard);
                    tempfile = exAgent.FileName;
                    #endregion
                    JLTBB02(dsSource);
                    break;
                case "JLTAV13AB05":
                    destfolder = SetFolder(Root, "整理");
                    #region====文件命名==============
                    order = "整理产量" + date;
                    DestFile = destfolder + "\\" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    if (System.IO.File.Exists(DestFile))
                    {
                        System.IO.File.Delete(DestFile);
                    }
                    System.IO.File.Copy(TemplatePath, DestFile);
                    exAgent.Open(DestFile);
                    exAgent.SetCurrentSheet("明细");
                    exAgent.FileName = DestFile;
                    exAgent.Save();
                    #endregion
                    JLTAV13AB05(dsSource);
                    exAgent.Close();
                    if (PrintType == "OpenExcel")
                    {
                        System.Diagnostics.Process.Start("EXCEL.EXE", DestFile);
                    }
                    break;
                case "JLTVKDOC":
                    destfolder = SetFolder(Root, "销售");
                    #region====文件命名==============
                    order = "接单工交明细表" + date;
                    DestFile = destfolder + "\\" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standard = "JLTVKPOSPR";
                    exAgent.CreateNewSheet(temp + ".xls", Standard);
                    tempfile = exAgent.FileName;
                    #endregion
                    JLTVKDOC(dsSource);
                    break;
                case "JLTVKCOST":
                    destfolder = SetFolder(Root, "财务");
                    #region====文件命名==============
                    order = "销售工交明细表" + date;
                    DestFile = destfolder + "\\" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standard = "JLTVKCOST";
                    exAgent.CreateNewSheet(temp + ".xls", Standard);
                    tempfile = exAgent.FileName;
                    #endregion
                    JLTVKCOST(dsSource);
                    break;
                case "JLTCOSTLIST":
                    destfolder = SetFolder(Root, "财务");
                    #region====文件命名==============
                    order = "销售接单工交表" + date;
                    DestFile = destfolder + "\\" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standard = "JLTCOSTLIST";
                    exAgent.CreateNewSheet(temp + ".xls", Standard);
                    tempfile = exAgent.FileName;
                    #endregion
                    JLTCOSTLIST(dsSource);
                    break;
                case "JLTCOSTTOT":
                    destfolder = SetFolder(Root, "财务");
                    #region====文件命名==============
                    order = "销售工交汇总表" + date;
                    DestFile = destfolder + "\\" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standard = "JLTCOSTTOT";
                    exAgent.CreateNewSheet(temp + ".xls", Standard);
                    tempfile = exAgent.FileName;
                    #endregion
                    JLTCOSTTOT(dsSource);
                    break;
                case "JLTWBZZM":
                    destfolder = SetFolder(Root, "生产进度");
                    #region====文件命名==============
                    order = "织造车间月产量" + date;
                    DestFile = destfolder + "\\" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standard = "JLTWBZZM";
                    exAgent.CreateNewSheet(temp + ".xls", Standard);
                    tempfile = exAgent.FileName;
                    #endregion
                    JLTWBZZM(dsSource);
                    break;

                    #endregion





            }
            return filename;
        }

    }
}
